from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-27 14:06:11.838188
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 27, Feb, 2021
Time: 14:06:15
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4311
Nobs: 215.000 HQIC: -47.2719
Log likelihood: 2487.37 FPE: 1.67006e-21
AIC: -47.8420 Det(Omega_mle): 1.10926e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.469044 0.135771 3.455 0.001
L1.Burgenland 0.072791 0.069657 1.045 0.296
L1.Kärnten -0.217561 0.059149 -3.678 0.000
L1.Niederösterreich 0.136351 0.159268 0.856 0.392
L1.Oberösterreich 0.253290 0.141245 1.793 0.073
L1.Salzburg 0.215881 0.075228 2.870 0.004
L1.Steiermark 0.096416 0.100783 0.957 0.339
L1.Tirol 0.129845 0.067858 1.913 0.056
L1.Vorarlberg -0.013462 0.061472 -0.219 0.827
L1.Wien -0.127375 0.132856 -0.959 0.338
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.473371 0.163340 2.898 0.004
L1.Burgenland 0.008888 0.083801 0.106 0.916
L1.Kärnten 0.351828 0.071160 4.944 0.000
L1.Niederösterreich 0.106740 0.191608 0.557 0.577
L1.Oberösterreich -0.124953 0.169926 -0.735 0.462
L1.Salzburg 0.198721 0.090503 2.196 0.028
L1.Steiermark 0.201896 0.121248 1.665 0.096
L1.Tirol 0.140477 0.081636 1.721 0.085
L1.Vorarlberg 0.156510 0.073954 2.116 0.034
L1.Wien -0.500021 0.159833 -3.128 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.315340 0.062663 5.032 0.000
L1.Burgenland 0.099872 0.032149 3.107 0.002
L1.Kärnten -0.017226 0.027299 -0.631 0.528
L1.Niederösterreich 0.097804 0.073508 1.331 0.183
L1.Oberösterreich 0.297181 0.065190 4.559 0.000
L1.Salzburg -0.000083 0.034720 -0.002 0.998
L1.Steiermark -0.004984 0.046515 -0.107 0.915
L1.Tirol 0.077958 0.031319 2.489 0.013
L1.Vorarlberg 0.098103 0.028372 3.458 0.001
L1.Wien 0.042483 0.061318 0.693 0.488
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218896 0.068182 3.210 0.001
L1.Burgenland -0.005309 0.034981 -0.152 0.879
L1.Kärnten 0.019011 0.029704 0.640 0.522
L1.Niederösterreich 0.043634 0.079982 0.546 0.585
L1.Oberösterreich 0.384958 0.070931 5.427 0.000
L1.Salzburg 0.087985 0.037778 2.329 0.020
L1.Steiermark 0.181711 0.050612 3.590 0.000
L1.Tirol 0.040112 0.034077 1.177 0.239
L1.Vorarlberg 0.085173 0.030870 2.759 0.006
L1.Wien -0.056885 0.066718 -0.853 0.394
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.511060 0.135426 3.774 0.000
L1.Burgenland 0.060046 0.069480 0.864 0.387
L1.Kärnten 0.015143 0.058999 0.257 0.797
L1.Niederösterreich -0.012144 0.158863 -0.076 0.939
L1.Oberösterreich 0.141299 0.140886 1.003 0.316
L1.Salzburg 0.062109 0.075036 0.828 0.408
L1.Steiermark 0.112836 0.100527 1.122 0.262
L1.Tirol 0.210646 0.067685 3.112 0.002
L1.Vorarlberg 0.026515 0.061316 0.432 0.665
L1.Wien -0.117622 0.132518 -0.888 0.375
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194397 0.097824 1.987 0.047
L1.Burgenland -0.016230 0.050188 -0.323 0.746
L1.Kärnten -0.004905 0.042617 -0.115 0.908
L1.Niederösterreich 0.081683 0.114754 0.712 0.477
L1.Oberösterreich 0.394991 0.101768 3.881 0.000
L1.Salzburg -0.019428 0.054202 -0.358 0.720
L1.Steiermark -0.007454 0.072615 -0.103 0.918
L1.Tirol 0.181288 0.048892 3.708 0.000
L1.Vorarlberg 0.043692 0.044291 0.986 0.324
L1.Wien 0.158689 0.095724 1.658 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.245572 0.125786 1.952 0.051
L1.Burgenland 0.046865 0.064534 0.726 0.468
L1.Kärnten -0.037372 0.054799 -0.682 0.495
L1.Niederösterreich -0.031791 0.147554 -0.215 0.829
L1.Oberösterreich -0.074092 0.130857 -0.566 0.571
L1.Salzburg 0.055635 0.069695 0.798 0.425
L1.Steiermark 0.396570 0.093371 4.247 0.000
L1.Tirol 0.463513 0.062867 7.373 0.000
L1.Vorarlberg 0.155305 0.056951 2.727 0.006
L1.Wien -0.217659 0.123085 -1.768 0.077
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123504 0.151195 0.817 0.414
L1.Burgenland 0.021536 0.077570 0.278 0.781
L1.Kärnten -0.070474 0.065868 -1.070 0.285
L1.Niederösterreich 0.204130 0.177360 1.151 0.250
L1.Oberösterreich -0.019341 0.157290 -0.123 0.902
L1.Salzburg 0.253651 0.083773 3.028 0.002
L1.Steiermark 0.143601 0.112232 1.280 0.201
L1.Tirol 0.049126 0.075566 0.650 0.516
L1.Vorarlberg 0.064215 0.068455 0.938 0.348
L1.Wien 0.233509 0.147948 1.578 0.114
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.572611 0.081208 7.051 0.000
L1.Burgenland -0.037276 0.041663 -0.895 0.371
L1.Kärnten -0.015552 0.035378 -0.440 0.660
L1.Niederösterreich 0.001087 0.095262 0.011 0.991
L1.Oberösterreich 0.304208 0.084482 3.601 0.000
L1.Salzburg 0.019281 0.044996 0.429 0.668
L1.Steiermark -0.004202 0.060281 -0.070 0.944
L1.Tirol 0.077348 0.040587 1.906 0.057
L1.Vorarlberg 0.119980 0.036768 3.263 0.001
L1.Wien -0.030090 0.079464 -0.379 0.705
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137425 0.045087 0.198840 0.250048 0.064231 0.127960 -0.037173 0.170345
Kärnten 0.137425 1.000000 0.002817 0.196416 0.166223 -0.122605 0.151228 0.009966 0.316920
Niederösterreich 0.045087 0.002817 1.000000 0.285717 0.069022 0.236732 0.156035 0.048099 0.354311
Oberösterreich 0.198840 0.196416 0.285717 1.000000 0.292647 0.282027 0.105733 0.071635 0.134461
Salzburg 0.250048 0.166223 0.069022 0.292647 1.000000 0.133424 0.054040 0.087248 -0.006388
Steiermark 0.064231 -0.122605 0.236732 0.282027 0.133424 1.000000 0.117595 0.114232 -0.112805
Tirol 0.127960 0.151228 0.156035 0.105733 0.054040 0.117595 1.000000 0.181624 0.163668
Vorarlberg -0.037173 0.009966 0.048099 0.071635 0.087248 0.114232 0.181624 1.000000 0.024962
Wien 0.170345 0.316920 0.354311 0.134461 -0.006388 -0.112805 0.163668 0.024962 1.000000